package com.yiran.controller;

import com.yiran.pojo.Result;
import com.yiran.pojo.User;
import com.yiran.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.security.NoSuchAlgorithmException;
import java.util.List;

@RestController
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/user/register/{username}/{password}")
    public Result register(@PathVariable String username,@PathVariable String password) throws NoSuchAlgorithmException {
        log.info("收到注册服务");
        User user=userService.register(username,password);
        return Result.success(user);
    }

    @GetMapping("/user/login/{username}/{password}")
    public Result<User> login(@PathVariable String username,@PathVariable String password) throws NoSuchAlgorithmException {
        return Result.success(userService.login(username,password));
    }

    /**
     * 根据拿所有员工信息
     */
    @GetMapping("/user/userinfo")
    public List<User> getUsers(){
        return userService.list();
    }

}
